package com.blog;
public class day02OuterClass {
	int i =5;
	static String str = "Outer Class Static  Variable";
	private String OuterClassPrivateVariable = "Outer Class Private Variable";
	
	// 一、外部类访问内部类
	void viewInnerClass() {
		// 1. 非静态访问 非静态内部类
		// 1.1 访问非静态成员，则可直接访问 new
		System.out.println(new InnerClass().innerClassStr);
		
		// 1.2 访问静态成员，则需先new再访问
		// The static field day02OuterClass.InnerClass.innerStr should be accessed in a static way
		new InnerClass();
		System.out.println( InnerClass.innerStaticStr);
		
		// 
		System.out.println(day02OuterClass.InnerClass.innerStaticStr);
	}
	
	static void staticViewInnerClass() {
		// 静态方法访问非静态
		//System.out.println(new InnerClass().innerClassStr);
		System.out.println(new day02OuterClass().new InnerClass().innerClassStr);
		
		// 访问静态

		
		System.out.println(new day02OuterClass().new InnerClass().innerStaticStr);
		
		// The static field day02OuterClass.InnerClass.innerStr should be accessed in a static way
		//System.out.println(new InnerClass().innerStr);
		
	}
	
	public static void main(String[] args) {
		// view Inner Class
		// No enclosing instance of type day02OuterClass is accessible. Must qualify the allocation with an enclosing instance of type day02OuterClass (e.g. x.new A() where x is an instance of day02OuterClass).
		//System.out.println(new InnerClass().innerClassStr);
		
	}
	
	
	// not static inner class
	class InnerClass{
		String innerClassStr = "inner class Variable";
		
		//The field innerStr cannot be declared static in a non-static inner type, unless initialized with a constant expression
		//static  String innerStr = "INNER CLASS STATIC VARIABLE";  定义出现错误
		static final String innerStaticStr = "INNER CLASS STATIC VARIABLE";
		
		void ViewOuterClassVariable() {
			System.out.println("------ViewOuterClassVariable--------");
			System.out.println(i);
			System.out.println(str);
			System.out.println(OuterClassPrivateVariable);
		}
	}
	
	//  static inner class
	static  class StaticInnerClass{
		String staticInnerClassStr = "Static inner class variable";
		static String StaticInnerClassStaticStr = "Static inner class  static variable";
		
		void ViewOuterClassVariable() {
			//Cannot make a static reference to the non-static field i
			//System.out.println(i);
			System.out.println(new day02OuterClass().i);
			System.out.println(new day02OuterClass().OuterClassPrivateVariable);
			
			System.out.println(str);
		}
		
		static void StaticViewOuterClassVariable() {
			System.out.println(new day02OuterClass().i);
			System.out.println(new day02OuterClass().OuterClassPrivateVariable);
			
			System.out.println(str);
		}
	}
}
